package com.mtw.bbs.article.feign;


import com.mtw.bbs.article.pojo.form.ReplyCountForm;
import com.mtw.bbs.article.pojo.vo.ReplyCountVo;
import com.mtw.bbs.common.core.vo.Result;
import com.mtw.bbs.common.web.interceptor.BaseFeignInterceptor;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

import static com.mtw.bbs.common.core.constant.ApiPrefix.API_PREFIX_REPLY;


/**
 * 评论 Feign接口类
 */
@FeignClient(
        value = "bbs-article",
        contextId = "replyClientI",
        configuration = BaseFeignInterceptor.class,
        fallback = ReplyClient.ReplyClientFallback.class
)
public interface ReplyClient {



    @ApiOperation(value = "根据用业务id和实体id获取评论数量", notes = "")
    @PostMapping(value = API_PREFIX_REPLY+"/getReplyCount",headers = "Content-Type=application/json")
    Result<ReplyCountVo> getCountByBusAndMessageId(@RequestBody ReplyCountForm form);


    @ApiOperation(value = "根据用业务id和实体id集合获取评论数量", notes = "")
    @PostMapping(value = API_PREFIX_REPLY+"/getReplyCountList",headers = "Content-Type=application/json")
    Result<List<ReplyCountVo>> getCountByBusAndMessageIds(@RequestBody ReplyCountForm form);



    /**
     * Feign失败配置
     */
    @Component("replyClient")
    class ReplyClientFallback implements ReplyClient {


        @Override
        public Result<ReplyCountVo> getCountByBusAndMessageId(ReplyCountForm form) {
            return Result.fail("获取失败");
        }

        @Override
        public Result<List<ReplyCountVo>> getCountByBusAndMessageIds(ReplyCountForm form) {
            return Result.fail("获取失败");
        }
    }

}
